package interpreter.practice_02;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

/**
 * 此代码来自b站
 *
 * @author yi qiang
 * @date 2021/6/20 22:38
 */
public class Client {
    public static void main(String[] args) throws IOException {
        String expStr=getExpStr();
        HashMap<String, Integer> val = getValue(expStr);
        Calculate calculate=new Calculate(expStr);
        System.out.print("运算结果："+expStr+"="+calculate.run(val));
    }

    public static String getExpStr() throws IOException {
        System.out.print("请输入表达式：");
        return new BufferedReader(new InputStreamReader(System.in)).readLine();
    }


    public static HashMap<String,Integer> getValue(String expStr) throws IOException {
        HashMap<String, Integer> map=new HashMap<>(8);
        for(char ch:expStr.toCharArray()){
            if(ch !='+' && ch !='-'){
                System.out.print("请输入"+ch+"的值:");
                String s = new BufferedReader(new InputStreamReader(System.in)).readLine();
                map.put(String.valueOf(ch),Integer.valueOf(s));
            }
        }
        return map;
    }

}
